<template>
  <div class="profile-settings">
    <h2>基本信息设置</h2>

    <!-- 用户名修改表单 -->
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="用户名称">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="form.email"></el-input>
      </el-form-item>
      <el-form-item>
       <el-button type="primary" @click="saveChanges">保存修改</el-button>
      </el-form-item>
     </el-form>
   
  </div>
</template>

<script>
import {updateById,getAdminInfo} from '@/api/user'
import { mapGetters } from 'vuex';
export default {
  data() {
    return {
      form: {
        username: "", // 用户名
        password: "", // 密码
        email: "", // 邮箱
      },
    };
  },
  computed:{
   ...mapGetters(["uid"])
  },
  mounted(){
   this.getAdminInfo()
  },
  methods: {
   async saveChanges() {
      const param={
       username:this.form.username,
       password:this.form.password,
       email:this.form.email,
       aid:this.uid
      }
      const res=await updateById(param);
       if(res.code==200){
        this.$message({
          message: '修改成功',
          type: 'success'
        });
       }
       else{
        this.$message({
          message: '修改有误',
          type: 'warning'
        });
       }
    },
   async getAdminInfo(){
     const res=await getAdminInfo(this.uid)
     
     if(res.code=200){
      this.form = res.data.matter;
      console.log(this.form);
     }
    }
  },
};
</script>

<style lang="scss" scoped>

/* 添加一些样式以美化页面 */
.profile-settings {
  max-width: 400px;
  margin: auto;
  padding: 20px;
}

.form-group {
  margin-bottom: 15px;
}

label {
  display: block;
  margin-bottom: 5px;
}
</style>
